#!/usr/bin/python

from xml.dom.minidom import Document


def createxml(name, levels):
	"""
	Creates a xml string with custom criteria and levels.
	"""
	dom = Document()
	
	root = dom.createElement('criteria')
	root.setAttribute('name', name)
	dom.appendChild(root)
		
	for record in levels:
		level = dom.createElement('level')
		(weight, caption) = record
		level.setAttribute('weight', str(weight))
		level.setAttribute('caption', caption)
		root.appendChild(level)
	
	return dom.toxml()

def main():
	"""
	Test function. Creates test xml for a criteria.
	"""
	dict = {}
	levels = []
	levels.append((1, "Very low"))
	levels.append((2, "Low"))
	levels.append((3, "Medium"))
	levels.append((4, "High"))
	levels.append((5, "Very high"))
	dict['Wow'] = levels

	for criteria in dict.keys():
		filename = criteria.lower() + ".xml"
		f = open(filename, "w")
		xml = createxml(criteria, dict[criteria])
		f.write(xml)
		f.close()

if __name__ == "__main__":
		main()


